<?php

/**
 * +------ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER * ---------+
 * +----------------------------------------------------------------------------+
 * | PHPKiisf - Keep It in Simple Framework										|
 * | Version 1.0																|
 * | Copyright (C) <2013>  Mario Cezzare <mcezzare@gmail.com>					|
 * | Blog: http://mcezzare.blogspot.com.br										|
 * |																			|
 * | This program is part of PHPKiisf, and is free software: you can			|
 * | redistribute it and/or modify it under the terms of the GNU 				|
 * | General Public License as published by										|
 * | the Free Software Foundation, either version 3 of the License, or			|
 * | (at your option) any later version.										|
 * |																			|
 * | This program is distributed in the hope that it will be useful,			|
 * | but WITHOUT ANY WARRANTY; without even the implied warranty of				|
 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				|
 * | GNU General Public License for more details.								|
 * | You should have received a copy of the GNU General Public License			|
 * | along with this program.  If not, see <http://www.gnu.org/licenses/>.		|
 * +----------------------------------------------------------------------------+
 * | Author : <Mario Cezzare Angelicola Chiodi> <mcezzare@gmail.com>			|
 * +----------------------------------------------------------------------------+
 * | Contributors																|
 * |																			|
 * +----------------------------------------------------------------------------+
 *
 */
/**
 * @package	Models
 * @access	public
 * @since	2013-03-08
 * @author	Mario Cezzare <mcezzare@gmail.com>
 */

/**
 * DESCRIPTION
 * This is the default model for the fmwk
 *
 *
 */
class default_model {

	/**
	 * Version
	 * @var float
	 */
	private static $version = 1.0 ;

	/**
	 * To initialize methods on scaffold
	 *
	 * @var string
	 */
	public $init_table_name ;

	/**
	 * Table properties
	 * @var array
	 */
	public $table ; //*

	/**
	 * Table columns
	 * @var array
	 */
	public $fields ; //* columns

	/**
	 * Table indexes and keys
	 * @var array
	 */
	public $indexes ; //* keys

	/**
	 * To query Database objects
	 *
	 * @var default_dao
	 */
	private $dao ;
	
	/**
	 * will be used for scaffold
	 * @var array
	 */
	private $config ;

	public function __construct( $init_table_name = null ) {

		if ( $this->init_table_name !== null ) {
			$this->set_init_table_name( $init_table_name ) ;
		}

		$this->table = array() ;
		$this->fields = array() ;
		$this->indexes = array() ;
		$this->dao = new default_dao() ;
	}

	/**
	 * Called by autoloader
	 *
	 * @return [type] [description]
	 */
	public static function init() {

	}

	public function remove_dao_information() {
		$this->dao = null ;
	}

	/**
	 * Get value of atribute, if it exists
	 *
	 * @param string $name  atribute name
	 * @param mixed $value atribute valule
	 */
	public function __get( $name ) {
		if ( isset( $this->$name ) ) {
			return $this->$name ;
		} else {
			return false ;
		}
	}

	/**
	 * Set value of atribute
	 *
	 * @param string $name  atribute name
	 * @param mixed $value atribute valule
	 */
	public function __set( $name , $value ) {
		if ( isset( $this->$name ) ) {
			$this->$name = $value ;
		} else {
			return false ;
		}
	}

	/**
	 * Alias function
	 * @param type $name
	 * @return type
	 */
	public function get( $name ) {
		return $this->__get( $name ) ;
	}

	/**
	 * Alias function
	 *
	 * @param type $name
	 * @param type $value
	 * @return type
	 */
	public function set( $name , $value ) {
		return $this->__set( $name , $value ) ;
	}

	public function get_table() {
		return $this->table ;
	}

	public function set_table( $table ) {
		$this->table = $table ;
	}

	public function get_fields() {
		return $this->fields ;
	}

	public function set_fields( $fields ) {
		$this->fields = $fields ;
	}

	public function get_indexes() {
		return $this->indexes ;
	}

	public function set_indexes( $indexes ) {
		$this->indexes = $indexes ;
	}

	public function get_init_table_name() {
		return $this->init_table_name ;
	}

	public function set_init_table_name( $init_table_name ) {
		$this->init_table_name = $init_table_name ;
	}

	public function scaffold() {
		/**
		 * create basic properties
		 */
		$this->set_table( $this->dao->get_table_properties( $this->get_init_table_name() ) ) ;
		$this->set_fields( $this->dao->get_columns_from_table( $this->get_init_table_name() ) ) ;
		$this->set_indexes( $this->dao->get_table_indexes( $this->get_init_table_name() ) ) ;

		$return = array(
			"table" => $this->get_table() ,
			"fields" => $this->get_fields() ,
			"indexes" => $this->get_indexes() ,
				) ;

		return $return ;
	}

}

?>